package day20180129.designMode.one_Iterater;

/**
 * Created by 14394 on 2018/1/29.
 */
//书架，代表集合
public class BookShelf implements Aggregate{

    private Book[] books;

    private int last = 0;

    public BookShelf(int maxsize){
        this.books = new Book[maxsize];
    }

    public Book getBookAt(int index){
        return books[index];
    }

    public void appendBook(Book book){
        this.books[last] = book;
        last++;
    }

    public int getLength(){
        return  last;
    }

    @Override
    public IteratorPattern iterator() {//实现抽象迭代方法
        return new BookShelfIterator(this);
    }
}
